<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信扫码结果</title>
    <!-- 导入vue和axios的核心js -->
    <script src="./plugins/vue/dist/vue.js"></script>
    <script src="./plugins/axios/dist/axios.js"></script>
    <script src="./js/axios.common.js"></script>
</head>
<body>
<div id="app">
    <h2>微信扫码成功~~~</h2>
</div>
<script type="text/javascript">
    new Vue({
        el: "#app",
        methods: {},
        mounted() {
            //获取地址栏参数
            let code = this.getParameter("code")
            alert(code)
            //发送请求到我们后端项目
            this.$http.get("/lrc/wechatLogin/" + code).then(res => {
                let {success, msg, data} = res.data
                if (success) {
                    //登录成功
                    localStorage.setItem("userToken", data.userToken);
                    localStorage.setItem("loginUser", data.loginUser);
                    location.href = "/index.html"
                } else if (msg == 'unbind') {
                    //未绑定，跳转到绑定页面（用户注册页面），提交表单（相当于注册，后端需要通过access_token和openid获取微信用户个人信息）
                    alert("请绑定用户！");
                    location.href = "/WxUser.html?access_token=" + data.access_token + "&openid=" + data.openid
                } else {
                    alert(msg)
                }
            })
        }
    })
</script>
</body>
</html>